package org.jeecg.modules.wlhy.customer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.modules.wlhy.customer.entity.HyCustomerCompany;
import org.jeecg.modules.wlhy.customer.mapper.HyCustomerCompanyMapper;
import org.jeecg.modules.wlhy.customer.service.IHyCustomerCompanyService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @Description: hy_customer_company
 * @Author: jeecg-boot
 * @Date:   2021-01-17
 * @Version: V1.0
 */
@Service
public class HyCustomerCompanyServiceImpl extends ServiceImpl<HyCustomerCompanyMapper, HyCustomerCompany> implements IHyCustomerCompanyService {

    @Override
    @Cacheable(unless="#result == null", cacheNames= CacheConstant.CACHE_CUSTOMER_COMPANY_CONFIG, key="#customerId")
    public HyCustomerCompany getByCustomerId(String customerId) {
        HyCustomerCompany customerCompany = this.getOne(
                new QueryWrapper<HyCustomerCompany>()
                        .eq("customer_id", customerId)
                        .last("limit 1")
        );
        return customerCompany;
    }

    @Override
    public HyCustomerCompany getById(String id) {
        HyCustomerCompany customerCompany = this.getOne(
                new QueryWrapper<HyCustomerCompany>()
                        .eq("id", id)
        );
        return customerCompany;
    }

    @Override
    @CacheEvict(cacheNames= CacheConstant.CACHE_CUSTOMER_COMPANY_CONFIG, key="#hyCustomerCompany.customerId")
    public void edit(HyCustomerCompany hyCustomerCompany) {
        this.updateById(hyCustomerCompany);
    }
}
